﻿<Controls.Common:Gadget
    x:Class="Imagin.Gadgets.SearchGadget"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:Imagin.Gadgets"
    xmlns:Common="http://imagin.tech/imagin/common"
    xmlns:Controls.Common="http://imagin.tech/imagin/controls/common"
    mc:Ignorable="d"
    Title="Search"
    x:Name="PART_SearchGadget"
    MinHeight="65"
    MaxHeight="65"
    MinWidth="225"
    Width="525"
    MaxWidth="1200"
    SizeToContent="Height"
    WindowStartupLocation="CenterScreen">
    <Controls.Common:Gadget.Resources>
        <local:SearchProviderToImageConverter x:Key="SearchEngineToImageConverter"/>
    </Controls.Common:Gadget.Resources>
    <Border
        DataContext="{Binding ElementName=PART_SearchGadget}"
        MinWidth="250"
        MaxWidth="1200"
        Padding="7">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Rectangle 
                Fill="{DynamicResource Brush.Image.MouseOver}"
                Margin="-7,-7,7,-7"
                Width="7"/>
            
            <Controls.Common:MaskedImage 
                Grid.Column="1" 
                Cursor="Hand"
                Controls.Common:FrameworkElementExtensions.IsDragMoveEnabled="True"
                Margin="0,0,5,0"
                Source="{Binding Provider.Base, Converter={StaticResource SearchEngineToImageConverter}}"/>

            <ComboBox 
                Grid.Column="2"
                x:Name="PART_Providers"
                BorderThickness="0"
                ItemsSource="{Binding Providers}" 
                SelectedValue="{Binding Provider, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Name}"/>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
            
            <Controls.Common:TextBoxExt 
                Grid.Column="3"
                BorderThickness="0"
                CanUserClear="True"
                Entered="OnEntered"
                Margin="7,0,0,0"
                Padding="0"
                Placeholder="What would you like to search?"
                Text="{Binding Query, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
            
            <Controls.Common:MaskedButton 
                Grid.Column="4" 
                Click="OnSearched" 
                Padding="7,0" 
                Source="pack://application:,,,/Imagin.Gadgets;component/Images/Search.png" 
                ToolTip="Search"/>

            <Controls.Common:MaskedDropDownButton 
                Grid.Column="5" 
                DropDownDataContext="{Binding Mode=OneWay}"
                Padding="7,0,0,0" 
                Source="pack://application:,,,/Imagin.Gadgets;component/Images/ArrowDownSmall.png" 
                ToolTip="Close">
                <Controls.Common:MaskedDropDownButton.DropDown>
                    <ContextMenu>
                        <MenuItem 
                            Command="{Binding CloseCommand}"
                            Header="Close"/>
                    </ContextMenu>
                </Controls.Common:MaskedDropDownButton.DropDown>
            </Controls.Common:MaskedDropDownButton>
        </Grid>
    </Border>
</Controls.Common:Gadget>
